package com.acwing.partition11;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/12/11 9:11
 */
public class AC1010拦截导弹 {

    private static final int N = 1010;
    private static int[] h = new int[N], stk = new int[N], f = new int[N];
    private static int n, top = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = ss.length;
        for (int i = 0; i < n; i++) h[i] = Integer.parseInt(ss[i]);
        //第一问，最长下降子序列
        int ans = 0;
        for (int i = 0; i < n; i++) {
            f[i] = 1;
            for (int j = 0; j < i; j++) {
                if (h[j] >= h[i]) f[i] = Math.max(f[i], f[j] + 1);
            }
            ans = Math.max(ans, f[i]);
        }
        writer.write(ans + "\n");
        //第二问，贪心算法
        for (int i = 0; i < n; i++) {
            //二分找前面最后一个比它大的数
            int l = 0, r = top;
            while (l < r) {
                int mid = l + r >> 1;
                if (stk[mid] >= h[i]) r = mid;
                else l = mid + 1;
            }
            if (l >= top) top++;
            stk[l] = h[i];
        }
        writer.write(top + "\n");
        writer.flush();
    }
}
